/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bl;

import common.Common;
import dal.LaborDA;
import dal.QueryExecuter;
import entities.Labor;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JComboBox;

/**
 *
 * @author MinhDuc
 */
public class LaborBO {

    Vector<Labor> data = new Vector<>();
    QueryExecuter query = new QueryExecuter();
    LaborDA laborDA = new LaborDA();
    private QueryExecuter execute = new QueryExecuter();

    public LaborBO() {
    }

    public boolean addLabor(Labor labor) {
        String insertLabor = "insert into Labor(Address,Building,Experience,FamilyDetail,FullName,"
                + "Gender,Height,LaborID,[Permanent/Temporary],PersonRefer,PhoneNumber\n"
                + ",SalaryGrade,Status,Weight) values('" + labor.getAddress() + "','" + labor.getBuilding()
                + "','" + labor.getExperience() + "','" + labor.getFamilyDetail() + "','" + labor.getName()
                + "'," + (new Common()).checkBoolean(labor.isGender()) + ",'" + labor.getHeight() + "','"
                + labor.getLaborID() + "'," + (new Common()).checkBoolean(labor.isPermanent())
                + ",'" + labor.getPersonRefer() + "','" + labor.getPhoneNumber() + "','" + labor.getSalaryGrade() + "','"
                + labor.getStatus() + "','" + labor.getWeight() + "')";
        int rt = execute.updateQuerry(insertLabor);
        return rt > 0 ? true : false;
    }

    public Vector<Labor> getAll() {
        data = laborDA.getAll();
        return data;
    }

    public void addComboBox(JComboBox comboBox) {
        try {
            String sql = "SELECT SalaryGrade from Salary";
            ResultSet rs = query.exeQuerry(sql);
            while (rs.next()) {
                String str = rs.getString("SalaryGrade");
                comboBox.addItem(str);
            }
        } catch (SQLException ex) {
            Logger.getLogger(LaborBO.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
